package com.bean;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.Date;
import java.util.List;

public class Post {

    /**
     * 帖子ID
     */
    @NotNull
    int postID;
    /**
     * 帖子主题
     */
    @NotNull
    @Size(min = 1,max = 50)
    String topic;
    /**
     * 帖子内容
     */
    @NotNull
    @Size(min = 10 , max = 500)
    String content;
    /**
     * 发帖人
     */
    @NotNull
    User poster;
    /**
     * 发帖时间
     */
    @NotNull
    Date postedTime;

    /**
     * 帖子点击次数
     */
    @NotNull
    int clickCount;
    /**
     * 跟帖内容列表
     */
    List<Comment> commentList;
    /**
     * 帖子状态
     * state=0 帖子被删除
     * state=1 帖子正常
     * state=2 帖子置顶
     */
    @NotNull
    int state;

    /**
     * 根据 postID 生成Post对象
     * @param postID
     */
    public Post(int postID) {
        this.postID = postID;
    }

    /**
     * 根据 postID， topic,content, poster, postedTime, clickCount, state 构建Post
     * @param postID
     * @param topic
     * @param content
     * @param poster
     * @param postedTime
     * @param clickCount
     * @param state
     */
    public Post(int postID, String topic,String content, User poster, Date postedTime, int clickCount, int state) {
        this.postID = postID;
        this.topic = topic;
        this.content = content;
        this.poster = poster;
        this.postedTime = postedTime;
        this.clickCount = clickCount;
        this.commentList = null;
        this.state = state;
    }


    /**
     * 根据 postID, topic, content, poster, postedTime, clickCount,commentList, state 构建Post
     * @param postID
     * @param topic
     * @param content
     * @param poster
     * @param postedTime
     * @param clickCount
     * @param commentList
     * @param state
     */
    public Post(int postID, String topic, String content, User poster, Date postedTime, int clickCount, List<Comment> commentList, int state) {
        this.postID = postID;
        this.topic = topic;
        this.content = content;
        this.poster = poster;
        this.postedTime = postedTime;
        this.clickCount = clickCount;
        this.commentList = commentList;
        this.state = state;
    }

    /**
     * 根据 topic, content, poster, postedTime, clickCount,commentList, state 构建Post
     * @param topic
     * @param content
     * @param poster
     * @param postedTime
     * @param clickCount
     * @param commentList
     * @param state
     */
    public Post(String topic, String content, User poster, Date postedTime, int clickCount, List<Comment> commentList, int state) {
        this.topic = topic;
        this.content = content;
        this.poster = poster;
        this.postedTime = postedTime;
        this.clickCount = clickCount;
        this.commentList = commentList;
        this.state = state;
    }


    public int getPostID() {
        return postID;
    }

    public void setPostID(int postID) {
        this.postID = postID;
    }

    public String getTopic() {
        return topic;
    }

    public void setTopic(String topic) {
        this.topic = topic;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public User getPoster() {
        return poster;
    }

    public void setPoster(User poster) {
        this.poster = poster;
    }

    public Date getPostedTime() {
        return postedTime;
    }

    public void setPostedTime(Date postedTime) {
        this.postedTime = postedTime;
    }


    public int getClickCount() {
        return clickCount;
    }

    public void addClickCount() {
        this.clickCount++;
    }


    public List<Comment> getCommentList() {
        return commentList;
    }

    public void setCommentList(List<Comment> commentList) {
        this.commentList = commentList;
    }

    public int getState() {
        return state;
    }

    public void setState(int state) {
        this.state = state;
    }
}
